package org.kotboot.module

import com.alibaba.fastjson.annotation.JSONField

data class Res<T>(
        var obj:T?,
        var msg:String? = "success",
        var code:ResCode? = ResCode.SUC,
        var status:String? = "success"
){
    companion object {
        fun OK(obj: Any? = "", msg: String? = "操作成功", code: ResCode? = ResCode.SUC,status: String? = "success" ): Res<Any> {
            return Res(obj,msg,code,status)
        }
        fun Err(obj:Any = "",msg:String = "error",code: ResCode = ResCode.ERR,status: String="error"):Res<Any>{
            return Res(obj,msg,ResCode.ERR,status)
        }
    }

    @JSONField(serialize = false) fun isOk() : Boolean {
        return ResCode.SUC.equals(this.code)
    }

    @JSONField(serialize = false) fun isErr() : Boolean{
        return ResCode.ERR.equals(this.code)
    }
}